上次介紹到比較簡單的客製化alert,今天介紹稍微進階一點。
這樣的客製化好處是在於你不用每次都還要宣告alertViewController,然後addAction,最後present,蠻麻煩的。
帶一個textField的alert:
TAlertView.showAlertWith(title: "123", message: "123", setCancelTitle: "cancel", setConfirmTitle: "sdwe", delegate: self) { textField in
textField.placeholder = "enter a number"
textField.keyboardType = .numberPad
} completion: { textfield in
GlobalAppSetting.shared.defaultADC = textfield.text!
self.setPlanTableView.reloadData()
}
兩個的:
TAlertView.showAlertWith(title: "title", message: "message", setCancelTitle: "setCancelTitle", setConfirmTitle: "setConfirmTitle", delegate: self) { textField1 in
textField1.placeholder = "placeholder1"
textField1.keyboardType = .numberPad
} textFieldSet2: { textField2 in
textField2.placeholder = "placeholder2"
textField2.keyboardType = .numberPad
} completion: { textField1, textField2 in
print("\(textField1.text!)")
print("\(textField2.text!)")
}